package cn.com.lyj6851.modules.edu.controller;


import cn.com.lyj6851.api.ApiResult;
import cn.com.lyj6851.constant.ShopConstants;
import cn.com.lyj6851.enums.ProductEnum;
import cn.com.lyj6851.modules.edu.service.EduCourseService;
import cn.com.lyj6851.modules.edu.vo.HomeVo;
import cn.com.lyj6851.modules.edu.vo.InitVo;
import cn.com.lyj6851.modules.edu.vo.TemplateVo;
import cn.com.lyj6851.modules.product.service.YdyStoreProductService;
import cn.com.lyj6851.modules.shop.service.YdySystemGroupDataService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * APP首页初始化数据
 * @author Administrator
 */
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "首页初始化", tags = "网校:首页初始化")
@RequestMapping("index")
public class InitController {

    private final YdySystemGroupDataService systemGroupDataService;
    private final YdyStoreProductService storeProductService;
    private final EduCourseService eduCourseService;

    @GetMapping("template")
    @ApiOperation(value = "模板数据",notes = "模板数据")
    public ApiResult<TemplateVo> template(){
        List<HomeVo> homeList = new ArrayList<HomeVo>();
        HomeVo search = new HomeVo(RandomUtil.randomInt(9999),"search","home","搜索","搜索商品",121);
        Map<String,Object> bannerMap = new HashMap<String,Object>();
        bannerMap.put("name","");
        bannerMap.put("style",1);
        bannerMap.put("list",systemGroupDataService.getDatas(ShopConstants.YDY_APP_BANNER));
        HomeVo banner = new HomeVo(RandomUtil.randomInt(9999),"banner","home","轮播图",bannerMap,121);

        HomeVo menu = new HomeVo(RandomUtil.randomInt(9999),"menu","home","菜单组",null,121);

        HomeVo goodsList = new HomeVo(RandomUtil.randomInt(9999),"goods-list","home","推荐课程",MapUtil.builder(new HashMap<String, Object>())
                .put("list", eduCourseService.getList(1,4, ProductEnum.TYPE_5.getValue()))
                .build(),121);

        //精品推荐
        HomeVo bastList = new HomeVo(RandomUtil.randomInt(9999),"bast-list","home","精品推荐",MapUtil.builder(new HashMap<String, Object>())
                .put("list", eduCourseService.getList(1,6, ProductEnum.TYPE_1.getValue()))
                .build(),121);
        // 热门榜单
        HomeVo hotList = new HomeVo(RandomUtil.randomInt(9999),"hot-list","home","热门榜单",MapUtil.builder(new HashMap<String, Object>())
                .put("list", eduCourseService.getList(1,6, ProductEnum.TYPE_2.getValue()))
                .build(),121);
        // 首发新品
        HomeVo firstList = new HomeVo(RandomUtil.randomInt(9999),"first-list","home","首发新品",MapUtil.builder(new HashMap<String, Object>())
                .put("list", eduCourseService.getList(1,8, ProductEnum.TYPE_3.getValue()))
                .build(),121);
        // 猜你喜欢
        HomeVo likeInfo = new HomeVo(RandomUtil.randomInt(9999),"like-info","home","猜你喜欢",MapUtil.builder(new HashMap<String, Object>())
                .put("list", eduCourseService.getList(1,10, ProductEnum.TYPE_4.getValue()))
                .build(),121);

        // tabbar
        Map<String,Object> tabbarMap = new HashMap<String,Object>();
        tabbarMap.put("color","#AEB3BE");
        tabbarMap.put("activeColor","#FE5550");
        tabbarMap.put("style",1);
        tabbarMap.put("isshow",true);
        tabbarMap.put("list",systemGroupDataService.getDatas(ShopConstants.YDY_APP_TABBAR));

        HomeVo tabular1 = new HomeVo(RandomUtil.randomInt(9999),"tabbar","tabbar","底部导航",tabbarMap,121);

        homeList.add(search);
        homeList.add(banner);
        homeList.add(menu);
        homeList.add(goodsList);
        homeList.add(bastList);
        homeList.add(hotList);
        homeList.add(firstList);
        homeList.add(likeInfo);

        TemplateVo templateVo = TemplateVo.builder()
                .home(homeList)
                .tabbar(CollUtil.newArrayList(tabular1))
                .build();
        return ApiResult.ok(templateVo,"模板数据");
    }

    @PostMapping("asyncLink")
    public ApiResult<Object> asyncLink(String routes){
        System.out.println(routes);
        return ApiResult.ok("asyncLink");
    }

    //初始化数据
    @GetMapping("init")
    public ApiResult<InitVo> init(){
        InitVo initVo = new InitVo();

        Map<String,Object> initMap = new HashMap<String,Object>();
        initMap.put("name","神笔码良教育");
        initMap.put("domain","http:www.ydy1024.top");
        initMap.put("logo","http:www.ydy1024.top");
        initMap.put("copyright", CollUtil.newArrayList("一点语科技版权所有","Copyright 2018-2020"));
        initVo.setInfo(initMap);
        initVo.setPayment(CollUtil.newArrayList("wechat","alipay","wallet"));
        Map<String,Object> shareMap = new HashMap<String,Object>();
        shareMap.put("title","邀请有好礼");
        shareMap.put("image","http://api.7wpp.com/uploads/20200414/4be7c944935a0fd6fc890f0214e6c3e0.jpg");
        shareMap.put("goods_poster_bg","http://api.7wpp.com/uploads/20200414/ab863760d809b0d0bfdf5eed24fecb61.png");
        shareMap.put("user_poster_bg","http://api.7wpp.com/uploads/20200414/000fada6ece566b12ccfc348861fedf6.png");
        shareMap.put("groupon_poster_bg","http://api.7wpp.com/uploads/20200912/c65b86f0ffb7f334fe7ca7528d2bb44a.png");
        initVo.setWechat(MapUtil.builder(new HashMap<String, Object>())
                .put("appid", "wx38939920ace0d244")
                .put("autologin", false).build());
        initVo.setShare(shareMap);
        initVo.setAddons(CollUtil.newArrayList("alioss","alisms","epay","geetest","loginbg","nkeditor"));

        Map<String, Object> chatMap = MapUtil.newHashMap();
        chatMap.put("type", "神笔码良教育");

        chatMap.put("basic", MapUtil.builder(new HashMap<String, Object>())
                .put("last_customer_service", 1)
                .put("allocate", "busy")
                .put("notice", "显示在用户端头部").build());

        chatMap.put("system", MapUtil.builder(new HashMap<String, Object>())
                .put("is_ssl", 1)
                .put("ssl_cert", "/www/wwwroot/api.7wpp.com/addons/shopro/library/chat/ssl/fullchain.pem")
                .put("ssl_key", "/www/wwwroot/api.7wpp.com/addons/shopro/library/chat/ssl/privkey.pem")
                .put("gateway_port", 1819)
                .put("gateway_num", 2)
                .put("business_worker_port", "2258")
                .put("business_worker_num", 4)
                .put("gateway_start_port", "2030").build());
        initVo.setChat(chatMap);
        return ApiResult.ok(initVo,"初始化数据");
    }
}
